03_ENGINEERING_NOTES PORTAL
Week 3 Algorithms · Dual Sovereign Core (AR / EN)
⚑ STRING COMPARISON & APPLIED OPTIMIZATION
AYMAN ELMASRY
Computational Creative Director · AI Prompt Engineer
Founder of Ayman Elmasry LLC
πŸ”’ ⚑ AEL Sovereign Seal (Active Master Verification)
{
  "ael_seal": "AEL CS Encyclopedia β€” Β© Ayman Elmasry",
  "owner": "Ayman Elmasry",
  "legal_entities": [
    "Ayman Elmasry LLC (UAE)",
    "Ayman Elmasry Advertising & Marketing (Egypt)"
  ],
  "syllabus_source": "Harvard CS50x 2026-2027",
  "domain": "Week 3: String Comparison & Applied Sorting",
  "document_type": "03_Engineering_Notes",
  "methodology": "8-Stage Sub-Silicon Execution Paradigm",
  "system_version": "v3.0"
}

Week 3 Engineering Notes: The String Comparison Trap

Section 1: The String Comparison Trap

When searching for a scalar integer within an array, developers evaluate numbers[i] == target. However, executing strings[i] == "David" in bare-metal C induces a catastrophic logical defect by comparing memory addresses rather than the underlying character stream.

===================================================================================
             STRING EQUALITY MEMORY TRAP
===================================================================================

  if (s == t)  ──>  Compares Address 0x100 with Address 0x200 (Result: FALSE!)
  
  if (strcmp(s, t) == 0) ──> Compares character values 'D','A','V','I','D' (Result: TRUE!)

===================================================================================
  • strcmp Routine: To evaluate actual character stream equality, developers must invoke strcmp, which returns exactly 0 when both strings match perfectly.

Section 2: Applied typedef struct Implementations

To ensure all function prototypes and subroutines recognize the custom structural declaration, it must be instantiated in the global scope prior to main.

  • Dot Notation: Developers deploy dot notation people[i].name to directly access internal member fields within the struct memory wrapper.

Section 3: Bubble Sort Architectural Optimization

In unoptimized Bubble Sort implementations, the execution loop continues exhaustive comparisons even if the target buffer achieves sorted equilibrium early. To optimize runtime, developers inject a tracking boolean bool swapped.

  • Conserving CPU Cycles: If a complete inner loop executes without a single swap, the execution halts instantly, conserving thousands of processor clock cycles.